package com.irdstudio.efp.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.rule.service.dao.TaxLoanInfoDao;
import com.irdstudio.efp.rule.service.domain.TaxLoanInfo;
import com.irdstudio.efp.rule.service.facade.TaxLoanInfoService;
import com.irdstudio.efp.rule.service.vo.TaxLoanInfoVO;

/**
 * <p>ServiceImpl: 获贷信息表<p>
 * @author ligm
 * @date 2019-05-15
 */
@Service("taxLoanInfoService")
public class TaxLoanInfoServiceImpl implements TaxLoanInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(TaxLoanInfoServiceImpl.class);

	@Autowired
	private TaxLoanInfoDao taxLoanInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertTaxLoanInfo(TaxLoanInfoVO inTaxLoanInfoVo) {
		logger.debug("当前新增数据为:"+ inTaxLoanInfoVo.toString());
		int num = 0;
		try {
			TaxLoanInfo taxLoanInfo = new TaxLoanInfo();
			beanCopy(inTaxLoanInfoVo, taxLoanInfo);
			num = taxLoanInfoDao.insertTaxLoanInfo(taxLoanInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(TaxLoanInfoVO inTaxLoanInfoVo) {
		logger.debug("当前删除数据条件为:"+ inTaxLoanInfoVo);
		int num = 0;
		try {
			TaxLoanInfo taxLoanInfo = new TaxLoanInfo();
			beanCopy(inTaxLoanInfoVo, taxLoanInfo);
			num = taxLoanInfoDao.deleteByPk(taxLoanInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxLoanInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(TaxLoanInfoVO inTaxLoanInfoVo) {
		logger.debug("当前修改数据为:"+ inTaxLoanInfoVo.toString());
		int num = 0;
		try {
			TaxLoanInfo taxLoanInfo = new TaxLoanInfo();
			beanCopy(inTaxLoanInfoVo, taxLoanInfo);
			num = taxLoanInfoDao.updateByPk(taxLoanInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxLoanInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public TaxLoanInfoVO queryByPk(TaxLoanInfoVO inTaxLoanInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inTaxLoanInfoVo);
		try {
			TaxLoanInfo queryTaxLoanInfo = new TaxLoanInfo();
			beanCopy(inTaxLoanInfoVo, queryTaxLoanInfo);
			TaxLoanInfo queryRslTaxLoanInfo = taxLoanInfoDao.queryByPk(queryTaxLoanInfo);
			if (Objects.nonNull(queryRslTaxLoanInfo)) {
				TaxLoanInfoVO outTaxLoanInfoVo = beanCopy(queryRslTaxLoanInfo, new TaxLoanInfoVO());
				logger.debug("当前查询结果为:"+ outTaxLoanInfoVo.toString());
				return outTaxLoanInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxLoanInfoVO> queryAllOwner(TaxLoanInfoVO taxLoanInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<TaxLoanInfoVO> list = null;
		try {
			List<TaxLoanInfo> taxLoanInfos = taxLoanInfoDao.queryAllOwnerByPage(taxLoanInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ taxLoanInfos.size());
			pageSet(taxLoanInfos, taxLoanInfoVo);
			list = (List<TaxLoanInfoVO>) beansCopy(taxLoanInfos, TaxLoanInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxLoanInfoVO> queryAllCurrOrg(TaxLoanInfoVO taxLoanInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<TaxLoanInfo> taxLoanInfos = taxLoanInfoDao.queryAllCurrOrgByPage(taxLoanInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+taxLoanInfos.size());
		List<TaxLoanInfoVO> list = null;
		try {
			pageSet(taxLoanInfos, taxLoanInfoVo);
			list = (List<TaxLoanInfoVO>) beansCopy(taxLoanInfos, TaxLoanInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxLoanInfoVO> queryAllCurrDownOrg(TaxLoanInfoVO taxLoanInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<TaxLoanInfo> taxLoanInfos = taxLoanInfoDao.queryAllCurrDownOrgByPage(taxLoanInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ taxLoanInfos.size());
		List<TaxLoanInfoVO> list = null;
		try {
			pageSet(taxLoanInfos, taxLoanInfoVo);
			list = (List<TaxLoanInfoVO>) beansCopy(taxLoanInfos, TaxLoanInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public List<TaxLoanInfoVO> queryAllByCondition(TaxLoanInfoVO taxLoanInfoVo) {
		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<TaxLoanInfo> taxLoanInfos = taxLoanInfoDao.queryAllByCondition(taxLoanInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ taxLoanInfos.size());
		List<TaxLoanInfoVO> list = null;
		try {
			pageSet(taxLoanInfos, taxLoanInfoVo);
			list = (List<TaxLoanInfoVO>) beansCopy(taxLoanInfos, TaxLoanInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

	@Override
	public TaxLoanInfoVO queryByLmtApplySeq(TaxLoanInfoVO inTaxLoanInfoVo) {
		logger.debug("当前查询参数信息为:"+ inTaxLoanInfoVo);
		try {
			TaxLoanInfo queryTaxLoanInfo = new TaxLoanInfo();
			beanCopy(inTaxLoanInfoVo, queryTaxLoanInfo);
			TaxLoanInfo queryRslTaxLoanInfo = taxLoanInfoDao.queryByLmtApplySeq(queryTaxLoanInfo);
			if (Objects.nonNull(queryRslTaxLoanInfo)) {
				TaxLoanInfoVO outTaxLoanInfoVo = beanCopy(queryRslTaxLoanInfo, new TaxLoanInfoVO());
				logger.debug("当前查询结果为:"+ outTaxLoanInfoVo.toString());
				return outTaxLoanInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
}
